package com.myajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.sun.corba.se.impl.io.OutputStreamHook;

/**
 * Servlet implementation class DbConnect
 */
public class DbConnect extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DbConnect() {
        super();
        // TODO Auto-generated constructor stub
    }
	
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stubString str=request.getParameter("name");
		String str=request.getParameter("name");
        PrintWriter out=response.getWriter();
	      try {
			out.print(printMe(str));
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
	    	  System.out.println("sql exception");
	    	  e.printStackTrace();
		} 
	      catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("sql exception");
		}
	      
	}


	private String printMe(String str)throws ClassNotFoundException, SQLException, IOException {
		String str1=str;
		String str2=null;
		RetriveData rd= new RetriveData(str1);
		ResultSet rs=rd.retrive();
		JdomCreate jd=new JdomCreate();
		str2=jd.makeXml(rs);
		return str2;
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
		
	}
